package priv.conceit.study.book.lambda.chapter5;

import priv.conceit.study.book.lambda.common.entity.Album;
import priv.conceit.study.book.lambda.common.entity.Artist;
import priv.conceit.study.book.lambda.common.entity.Track;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 高级集合类 和 收集器
 * 5.1
 * 方法引用
 *
 * @author Conceit
 * @since 1.0.0, 2021/9/27
 */
public class MethodReferences {

    public static void main(String[] args) {
        List<Album> albums=new ArrayList<>();
        Album album1=new Album("专辑1",
                Arrays.asList(new Track("专辑1-歌曲1",100),new Track("专辑1-歌曲2",200)),
                Arrays.asList(new Artist("zhaohang","china"),new Artist("zhaojie","china")));
        Album album2=new Album("专辑2",
                Arrays.asList(new Track("专辑2-歌曲1",300),new Track("专辑2-歌曲2",500)),
                Arrays.asList(new Artist("zhaohang","china"),new Artist("zhaojie","china")));
        albums.add(album1);
        albums.add(album2);



        List<String> albumNames;
        albumNames=albums.stream().map(album -> album.getName()).collect(Collectors.toList());
        //使用方法引用
        albumNames=albums.stream().map(Album::getName).collect(Collectors.toList());


    }
}
